package org.zheng.shop.repository;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.zheng.shop.entity.ConsultationSession;

/**
 * 咨询会话Repository
 */
@Repository
public interface ConsultationSessionRepository extends JpaRepository<ConsultationSession, Long> {
    
    /**
     * 根据用户ID和状态查找会话
     */
    Optional<ConsultationSession> findByUserIdAndStatusIn(Integer userId, List<ConsultationSession.SessionStatus> statuses);

    /**
     * 根据用户ID和状态查找会话，按更新时间倒序
     */
    List<ConsultationSession> findByUserIdAndStatusInOrderByUpdatedAtDesc(Integer userId, List<ConsultationSession.SessionStatus> statuses);
    
    /**
     * 根据用户ID查找所有会话，按更新时间倒序
     */
    List<ConsultationSession> findByUserIdOrderByUpdatedAtDesc(Integer userId);
    
    /**
     * 查找所有会话，按更新时间倒序
     */
    List<ConsultationSession> findAllByOrderByUpdatedAtDesc();

    /**
     * 根据状态查找会话
     */
    List<ConsultationSession> findByStatus(ConsultationSession.SessionStatus status);
}
